#notice= notice
=content_for :title do
  =tx "title"
  - if @search_mode.nil?
    - @search_mode = @search_results.get_context
=content_for :header do
  %h2
    =tx "title_main"
    %small
      - if @search_mode == 'genes'
        =tx "title_small"
      - else
        =tx "title_small_drugs"
      - if @related_source_gene
        = @related_source_gene
      %a(href="/faq#difference")
        =icon('question-sign')

.container-fluid.search-results
  .tabbable
    %ul.nav.nav-tabs
      %li.active
        %a(href="#successful" data-toggle="tab") Unique Matches
      %li
        %a(href="#failed" data-toggle="tab") Ambiguous or Unmatched

    .tab-content{style: "margin-top: 12px; background: white;"}
      .tab-pane.active#successful
        .row-fluid#container 
          .span12
            - definite_results = @search_results.definite_results
            - definite_no_interactions = @search_results.definite_no_interactions
            = render partial: 'interaction_claims/interaction_search_successful', locals: {definite_results: definite_results, definite_no_interactions: definite_no_interactions} #use @search_mode to determine type of view, just use one set of templates

      .tab-pane.fade#failed
        .row-fluid#container
          .span12
            - ambiguous_results = @search_results.ambiguous_results
            - ambiguous_no_interactions = @search_results.ambiguous_no_interactions
            - failed_results = @search_results.no_results_results
            - if failed_results.any?
              - failed_terms = failed_results.map{|result| result.search_term}.first.split(", ")
            - else
              - failed_terms = []
            = render partial: 'interaction_claims/interaction_search_failed', locals: {ambiguous_results: ambiguous_results, ambiguous_no_interactions: ambiguous_no_interactions, failed_terms: failed_terms}


:javascript
  $(".sidebar-toggle").on("click", function() {
    name = "#" + this.name;
    $(name).toggle();
  });

  $(".ambiguous.search-term").on("click", function() {
    name = "." + this.name;
    $(name).click();
  });

  $('table').each(function(index){
    $(this).find('> tbody > tr').hide().slice(0, 11).show();
  });
  $(".show-all").on("click", function() {
    var tbl = $('table');
    $("tbody > tr", tbl).show();
    $("#nrows", $(this).next().next().next()).html(tbl.find('tr:visible').length - 1);
  });
  $(".show-more").on("click", function() {
    var tbl = $('table');
    $("tbody > tr", tbl).slice(0, tbl.find('tr:visible').length + 10).show();
    $("#nrows", $(this).next().next()).html(tbl.find('tr:visible').length - 1);
  });
  $(".show-less").on("click", function() {
    var tbl = $('table');
    tbl.find('> tbody > tr').hide().slice(0, 11).show();
    $("#nrows", $(this).next()).html(tbl.find('tr:visible').length - 1);
  });
  $(document).ready(function () {
    var activeTab = $('#' + window.location.hash.substr(2));

    if(activeTab.length) {
      $('a[href="' + "#" + window.location.hash.substr(2) + '"]').trigger('click');
    } else {
      $('a[href="' + "#successful" + '"]').trigger('click');
    }
  });

  window.addEventListener("popstate", function() {
    var activeTab = $('#' + window.location.hash.substr(2));
    if (activeTab.length) {
      $('a[href="' + "#" + window.location.hash.substr(2) + '"]').trigger('click');
    } else {
      $('a[href="' + "#successful" + '"]').trigger('click');
    }
  });

  $(".tabbable > ul > li > a").click(function () {
    window.location.hash = "_" + $(this).attr('href').substr(1);
    return true;
  }); 
